import fractions, math

prec = 13

def closedform(n):
	gold = (1 + math.sqrt(5)) / 2
	return int((gold ** n - (1 - gold) ** n) / math.sqrt(5))

def pandigital(s, first):
	array = list(s)

	if first:
		counter = [0] * 10
		for i in array[:9]:
			i = int(i)
			if counter[i] > 0:
				return False
			counter[i] = 1
		if counter[0] != 0:
			return False
	else:
		#print s
		counter = [0] * 10
		for i in array[-9:]:
			i = int(i)
			if counter[i] > 0:
				return False
			counter[i] = 1
		if counter[0] != 0:
			return False
		
	return True

def int_len(x):
	return int(math.log(x, 10))

def getfirst(num, x):
	trim = int_len(num) - x + 1
	return num / (10 ** trim)

a = closedform(499)
b = closedform(500)
a_1 = a
b_1 = b
k = 500
while True:
	trueness = 0
	k += 1
	
	# add for the first 10
	# only trim if a_1 and b_1 are of the same length
	"""
	if int_len(a_1) == int_len(b_1):
		a_1 = getfirst(a_1, prec)
		b_1 = getfirst(b_1, prec)
	c_1 = a_1 + b_1
	a_1 = b_1
	b_1 = c_1
	if pandigital(str(c_1), True):
		#print k
		trueness += 1
	"""
	# add for the last 10
	c = (a + b) % (10 ** 20)
	a = b
	b = c
	if pandigital(str(c), False):
		print k
		trueness += 1

	if trueness == 2:
		print "Answer: %d" % k
		exit()

def all_perms(str):
	if len(str) <= 1:
		yield str
	else:
		for perm in all_perms(str[1:]):
			for i in range(len(perm)+1):
				yield perm[:i] + str[0:1] + perm[i:]

def consecutive(list):
	gcds = []

	gcd = list[0]
	for i in list:
		gcd = fractions.gcd(gcd, i)
	
	count = 0.0
	for i in list:
		count += 1
		if float(i) / float(gcd) != count:
			return False
	return True

list = []

prange = []
for i in range(0, 10):
	prange.append(str(i))

for perm in all_perms(prange):
	if int("".join(perm[1:4])) % 2 == 0 and \
		int("".join(perm[2:5])) % 3 == 0 and \
		int("".join(perm[3:6])) % 5 == 0 and \
		int("".join(perm[4:7])) % 7 == 0 and \
		int("".join(perm[5:8])) % 11 == 0 and \
		int("".join(perm[6:9])) % 13 == 0 and \
		int("".join(perm[7:10])) % 17 == 0:
			list.append(int("".join(perm)))

print sum(list)
